#include <get_srvs_from_json.h>
#include <get_msgs_from_json.h>

std::shared_ptr<agv_srvs::srv::DynParam::Request> get_agv_srvs_DynParam(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::DynParam::Request>();
    request->node_name = json_args["node_name"].asString();
    request->param_key = json_args["param_key"].asString();
    request->param_value = json_args["param_value"].asString();

    return request;
}

std::shared_ptr<agv_srvs::srv::StaticParam::Request> get_agv_srvs_StaticParam(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::StaticParam::Request>();
    request->action_name = json_args["action_name"].asString();
    return request;
}

std::shared_ptr<agv_srvs::srv::ChangeNavType::Request> get_agv_srvs_ChangeNavType(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::ChangeNavType::Request>();
    request->type = json_args["type"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::LocalOrder::Request> get_agv_srvs_V_localOrder(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::LocalOrder::Request>();
    request->recycle = json_args["recycle"].asBool();
    request->order = get_agv_msgs_V_order(json_args["order"]); // 假设你有一个函数来获取 order
    return request;
}

std::shared_ptr<agv_srvs::srv::InstantActions::Request> get_agv_srvs_V_instantActions(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::InstantActions::Request>();
    request->source = json_args["source"].asString();
    for (const auto &it : json_args["actions"])
    {
        request->actions.push_back(get_agv_msgs_V_action(it)); // 假设你有一个函数来获取 action
    }
    return request;
}

agv_msgs::msg::RelocateRadius get_agv_msgs_RelocateRadius(const Json::Value &json)
{
    agv_msgs::msg::RelocateRadius msg;
    msg.point = get_geometry_msgs_Point(json["point"]);
    msg.radius = json["radius"].asFloat();

    return msg;
}


std::shared_ptr<agv_srvs::srv::LidarCalib::Request> get_agv_srvs_LidarCalib(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::LidarCalib::Request>();
    request->trigger = json_args["trigger"].asInt();
    request->node0 = json_args["node0"].asInt();
    request->node1 = json_args["node1"].asInt();
    request->node2 = json_args["node2"].asInt();
    request->node3 = json_args["node3"].asInt();
    request->node4 = json_args["node4"].asInt();
    request->node5 = json_args["node5"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::QRCalib::Request> get_agv_srvs_QRCalib(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::QRCalib::Request>();
    request->trigger = json_args["trigger"].asInt();
    request->node0 = json_args["node0"].asInt();
    request->node1 = json_args["node1"].asInt();
    request->node2 = json_args["node2"].asInt();
    request->node3 = json_args["node3"].asInt();
    request->node4 = json_args["node4"].asInt();
    request->node5 = json_args["node5"].asInt();
    request->node6 = json_args["node6"].asInt();
    request->node7 = json_args["node7"].asInt();
    request->node8 = json_args["node8"].asInt();
    request->node9 = json_args["node9"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::SetLaserCalib::Request> get_agv_srvs_SetLaserCalib(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::SetLaserCalib::Request>();
    request->laser_num = json_args["laser_num"].asInt();
    for (const auto &it : json_args["x"])
    {
        request->x.push_back(it.asFloat());
    }
    for (const auto &it : json_args["y"])
    {
        request->y.push_back(it.asFloat());
    }
    for (const auto &it : json_args["yaw"])
    {
        request->yaw.push_back(it.asFloat());
    }
    for (const auto &it : json_args["enable"])
    {
        request->enable.push_back(it.asBool());
    }
    for (const auto &it : json_args["isInversion"])
    {
        request->isinversion.push_back(it.asBool());
    }
    return request;
}

std::shared_ptr<agv_srvs::srv::OdomCalib::Request> get_agv_srvs_OdomCalib(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::OdomCalib::Request>();
    request->start = json_args["start"].asInt();
    request->model = json_args["model"].asInt();
    request->vel = json_args["vel"].asFloat();
    request->oprange = json_args["oprange"].asFloat();
    return request;
}

std::shared_ptr<agv_srvs::srv::GetMapList::Request> get_agv_srvs_GetMapList(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::GetMapList::Request>();
    request->value = json_args["value"].asBool();
    return request;
}

// reflector_slam_ros::srv::reflector_NavTask get_reflector_slam_ros_reflector_NavTask(const Json::Value &json_args)
// {
//     reflector_slam_ros::srv::reflector_NavTask srv;
//     srv.Request.mode = json_args["mode"].asInt();
//     srv.Request.mapID = json_args["mapID"].asString();
//     return srv;
// }

// reflector_slam_ros::srv::save_reflector_map get_reflector_slam_ros_save_reflector_map(const Json::Value &json_args)
// {
//     reflector_slam_ros::srv::save_reflector_map srv;
//     srv.Request.mapID = json_args["mapID"].asString();
//     srv.Request.mode = json_args["mode"].asInt();
//     for (auto &it : json_args["reflector"])
//     {
//         srv.Request.reflector.push_back(get_reflector_slam_ros_reflectorLandmark(it));
//     }
//     return srv;
// }

std::shared_ptr<agv_srvs::srv::Relocate::Request> get_agv_srvs_Relocate(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::Relocate::Request>();
    request->mode = get_std_msgs_UInt8(json_args["mode"]);
    request->point_yaw = get_geometry_msgs_Pose2D(json_args["point_yaw"]);
    request->position_radius = get_agv_msgs_RelocateRadius(json_args["position_radius"]);
    for (const auto &it : json_args["position_region"])
    {
        request->position_region.push_back(get_geometry_msgs_Point(it));
    }
    if (json_args.isMember("zoneTag")) // 判断有无 zoneTag 输入
    {
        request->zonetag = get_std_msgs_String(json_args["zoneTag"]);
    }
    return request;
}

std::shared_ptr<agv_srvs::srv::SetOperationMode::Request> get_agv_srvs_SetOperationMode(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::SetOperationMode::Request>();
    request->mode = json_args["mode"].asString();
    request->submode = json_args["submode"].asString();
    request->sender = json_args["sender"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::FileTransform::Request> get_agv_ftp_log_file_transform(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::FileTransform::Request>();
    request->file_name = json_args["file_name"].asString();
    request->recfilesize = json_args["recfilesize"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::OutputInterface::Request> get_agv_srvs_OutputInterface(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::OutputInterface::Request>();
    for (const auto &it : json_args["index_level"])
    {
        request->index_level.push_back(get_agv_msgs_OutputPort(it));
    }
    return request;
}

std::shared_ptr<agv_srvs::srv::LogTransform::Request> get_agv_srvs_log_transform(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::LogTransform::Request>();
    request->log_status = json_args["log_status"].asInt();
    return request;
}

std::shared_ptr<std_srvs::srv::SetBool::Request> get_std_srvs_SetBool(const Json::Value &json_args)
{
    auto request = std::make_shared<std_srvs::srv::SetBool::Request>();
    request->data = json_args["data"].asBool();
    return request;
}

std::shared_ptr<agv_srvs::srv::EditMap::Request> get_agv_srvs_EditMap(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::EditMap::Request>();
    request->mapid = json_args["mapID"].asString();
    request->erase_action = get_agv_msgs_mapEdit_earse(json_args["earse_action"]);
    request->transform_action = get_agv_msgs_mapEdit_Transform(json_args["transform_action"]);
    return request;
}

std::shared_ptr<agv_srvs::srv::SetLoactionMode::Request> get_agv_srvs_SetLoactionMode(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::SetLoactionMode::Request>();
    request->mode = json_args["mode"].asInt();
    request->mapid = json_args["mapId"].asString();
    request->resolution = json_args["resolution"].asFloat();
    return request;
}

std::shared_ptr<agv_srvs::srv::SaveMap::Request> get_agv_srvs_SaveMap(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::SaveMap::Request>();
    request->name = json_args["name"].asString();
    return request; 
}

std::shared_ptr<agv_srvs::srv::AutoCalib::Request> get_agv_srvs_AutoCalib(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::AutoCalib::Request>();
    request->calib_cmd = json_args["calib_cmd"].asInt();
    request->seconds = json_args["seconds"].asFloat();
    request->code = json_args["code"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::LaserFilter::Request> get_agv_srvs_LaserFilter(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::LaserFilter::Request>();
    request->type = json_args["type"].asInt();
    request->invert = json_args["invert"].asBool();
    for (const auto &it : json_args["points"])
    {
        request->points.push_back(get_geometry_msgs_Point32(it));
    }
    return request;
}

std::shared_ptr<agv_srvs::srv::GetMapPoint::Request> get_agv_srvs_GetMapPoint(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::GetMapPoint::Request>();
    request->status = json_args["status"].asBool();
    return request;
}

std::shared_ptr<slam_ros_msgs::srv::ChangeMap::Request> get_slam_ros_msgs_ChangeMap(const Json::Value &json_args)
{
    auto request = std::make_shared<slam_ros_msgs::srv::ChangeMap::Request>();
    request->code = get_std_msgs_UInt8(json_args["code"]);
    request->mapid = json_args["mapId"].asString();
    request->mapnewid = json_args["mapNewId"].asString();
    request->keys = json_args["Keys"].asString();
    return request;
}

std::shared_ptr<slam_ros_msgs::srv::GetLandmarkLists::Request> get_slam_ros_msgs_GetLandmarkLists(const Json::Value &json_args)
{
    auto request = std::make_shared<slam_ros_msgs::srv::GetLandmarkLists::Request>();
    request->cmd = json_args["cmd"].asInt();
    return request;
}

std::shared_ptr<agv_srvs::srv::Version::Request> get_agv_srvs_Version(const Json::Value &json_args)
{
    return std::make_shared<agv_srvs::srv::Version::Request>(); // 直接返回一个新的请求
}

std::shared_ptr<agv_srvs::srv::FirmwareUpdate::Request> get_agv_srvs_FirmwareUpdate(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::FirmwareUpdate::Request>();
    request->fw_size = json_args["fw_size"].asInt();
    request->fw_name = json_args["fw_name"].asString();
    request->fw_md5 = json_args["fw_md5"].asString();
    request->fw_content = json_args["fw_content"].asString();
    request->is_test_version = json_args["is_test_version"].asBool();
    return request;
}

std::shared_ptr<agv_srvs::srv::FtpRequest::Request> get_agv_srvs_FtpRequest(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::FtpRequest::Request>();
    request->type = json_args["type"].asInt();
    request->user = json_args["user"].asString();
    request->passwd = json_args["passwd"].asString();
    return request;
}

std::shared_ptr<slam_ros_msgs::srv::Syncmap::Request> get_slam_ros_msgs_Syncmap(const Json::Value &json_args)
{
    auto request = std::make_shared<slam_ros_msgs::srv::Syncmap::Request>();
    request->opcode = json_args["opCode"].asInt();
    request->mapid = json_args["mapId"].asString();
    request->md5code = json_args["md5Code"].asString();
    return request;
}

std::shared_ptr<agv_srvs::srv::AvoidObstaUpdate::Request> get_agv_srvs_AvoidObstaUpdate(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::AvoidObstaUpdate::Request>();
    request->start = json_args["start"].asBool();
    return request;
}

std::shared_ptr<agv_srvs::srv::AvoidObstaSwitch::Request> get_agv_srvs_AvoidObstaSwitch(const Json::Value &json_args)
{
    auto request = std::make_shared<agv_srvs::srv::AvoidObstaSwitch::Request>();
    request->planname = json_args["planname"].asString();
    return request;
}
